#Maintainer: Juergen Hoetzel <juergen@archlinux.org>

pkgname=lablgtk2
pkgver=2.18.12
pkgrel=3
pkgdesc="An Objective Caml interface to gtk2"
arch=(loong64 x86_64)
license=('LGPL')
url="http://lablgtk.forge.ocamlcore.org/"
depends=('gtk2' 'librsvg')
makedepends=('ocaml' 'ocaml-compiler-libs' 'camlp5' 'camlp-streams' 'ocaml-findlib')
optdepends=('ocaml: for using the tools')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/garrigue/lablgtk/archive/${pkgver}.tar.gz" gcc10.patch '0001-Adapt-to-deprecations-in-5.0.patch')
sha512sums=('284a1234ae817c4df49809d28c103ca5e64046da5ec9ff28c6edc0ce999e9d3e6e180dd053f8b1663d4fb3b7ba19570d53b9441c8fa622add924e8d85e41b813'
            '0fcb9f333101c5ab04dde1729a9c9805e422f100f79ad8014a3cd8c5cb78d19344292e334d4cc70d3614a41a4e143a30cd707b67a8443fa8b6f8c8fc9d7f27d9'
            '0b61164cab4a541194eced8d74d8f3034efb08e04079645896487e57c4f629e88eb1da925a6c4d577e95f29d1222724ed74b8b7cf4e5b3cd83fba802f20dcab9')
options=(!makeflags staticlibs !lto)

prepare() {
  cd "${srcdir}/lablgtk-${pkgver}"
  patch -p1 -i "${srcdir}/0001-Adapt-to-deprecations-in-5.0.patch"
}

build() {
  cd "${srcdir}/lablgtk-${pkgver}"
  ./configure --prefix=/usr \
    --without-gnomeui \
    --without-gnomecanvas \
    --without-panel \
    --without-gtkspell \
    --without-gtksourceview \
    --without-gtksourceview2 \
    --without-glade
  sed -e "s|-O|$CFLAGS|" \
      -e "s|-shared|& -ccopt \"$LDFLAGS\"|" \
      -e "s|(CAMLMKLIB)|& -ldopt \"$LDFLAGS\"|" \
      -i src/Makefile
  make world
  make opt
}

package() {
  cd "${srcdir}/lablgtk-${pkgver}"
  make DESTDIR="${pkgdir}" old-install
  install -m644 META "${pkgdir}/usr/lib/ocaml/lablgtk2/"
}
